package notwork;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class TcpEchoClient {
    private Socket socket=null;

    public TcpEchoClient(String serverIP,int serverPort) throws IOException {
        socket=new Socket(serverIP,serverPort);
    }

    public void start(){
        Scanner scanner=new Scanner(System.in);
     try(InputStream inputStream=socket.getInputStream();
         OutputStream outputStream=socket.getOutputStream()){
         Scanner scannerNet=new Scanner(inputStream);
         PrintWriter writer=new PrintWriter(outputStream);

         while (true){
             String request=scanner.next();
             writer.println(request);
             writer.flush();
             String reponse=scannerNet.next();
             System.out.println(reponse);
         }
     } catch (IOException e) {
         throw new RuntimeException(e);
     }
    }

    public static void main(String[] args) throws IOException {
        TcpEchoClient client=new TcpEchoClient("127.0.0.1",5656);
client.start();
    }

}
